﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Net.Fan.SmallPig.DataBase;

namespace Net.Fan.SmallPig.DataAccess
{
    public class DynamicDA
    {
        public static DataTable GetRecentlyOperates()
        {
            string sql = "select top 10 d.*,u.TrueName,j.Summary from Dynamic d ,Users u,Jobs j where d.JobId=j.JobId and d.Operator=u.UserName order by d.HappenTime desc";

            //SqlParameter[] paras = new SqlParameter[0];
            //paras[0] = new SqlParameter("@UserId", userId);

            DataSet ds = DA_Base.RunReturnDataset(sql);
            return ds.Tables[0];
        }


        public static long AddNewDynamic(long jobId, string operate, string Operator)
        {


            string sql = "INSERT INTO Dynamic (JobId,  Operate, Operator, HappenTime) VALUES (@JobId,  @Operate, @Operator,GetDate()) ";
            sql += " select @@identity";
            SqlParameter[] paras = new SqlParameter[4];
            paras[0] = new SqlParameter("@JobId", jobId);
            paras[1] = new SqlParameter("@Operate", operate);
            paras[2] = new SqlParameter("@Operator", Operator);


            decimal dd = (decimal)DA_Base.ExecuteScalar(sql, paras);
            return Convert.ToInt64(dd);
        }
    }
}
